package LanQiaoCompetition2;

public class History_2017 {
    private static int[] numbers = new int[]{1,2,3,4,5,6,7,8,9};
    private static int sum = 0;
    public static void main(String args[]){
        print(0);
        System.out.println(sum);
    }

    private static void print(int point){

        if(point >= numbers.length-1){
            sum++;
            for(int n:numbers){
                System.out.print(n+" ");
            }
            System.out.println();
            return;
        }

        for(int i=point;i<=numbers.length-1;i++){
            change(point,i);
            print(point+1);
            change(point,i);
        }
    }

    private static void change(int n1,int n2){
        int center;
        if(n1==n2){
            return;
        }
        center = numbers[n1];
        numbers[n1] = numbers[n2];
        numbers[n2] = center;
    }


}
